
cmake_minimum_required(VERSION 3.16)

project(rdp_demo)


set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++20 -fPIC -Wall")

find_package(ECM ${KF5_MIN_VERSION} NO_MODULE)
set(CMAKE_MODULE_PATH  ${CMAKE_MODULE_PATH}  ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules )

set(QT_MAJOR_VERSION "5")
if (QT_MAJOR_VERSION STREQUAL "5")
set(QT_MAJOR_VERSION 5)
set(QT_MIN_VERSION "5.15.0")
elseif(QT_MAJOR_VERSION STREQUAL "6")
set(QT_MAJOR_VERSION 6)
set(QT_MIN_VERSION "6.4.0")
endif()
message(STATUS "QT_MAJOR_VERSION: ${QT_MAJOR_VERSION}")
message(STATUS "QT_MIN_VERSION: ${QT_MIN_VERSION}")

find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} CONFIG REQUIRED Core Gui Network Widgets)
find_package(FreeRDP 2.10 REQUIRED)
# message(STATUS "FreeRDP_INCLUDE_DIR: ${FreeRDP_INCLUDE_DIR}")
find_package(WinPR REQUIRED)
find_package(FreeRDP-Server REQUIRED)
find_package(XKB REQUIRED)


include(ECMGenerateExportHeader)
include(ECMAddTests)
include(ECMSetupVersion)
include(ECMQtDeclareLoggingCategory)
include(ECMEnableSanitizers)

# find_package(PkgConfig REQUIRED)
# pkg_check_modules(FFMPEG REQUIRED libavformat libavcodec  libavutil libswscale)
# if(FFMPEG_FOUND)
#     message(STATUS "FFMPEG_FOUND: ${FFMPEG_FOUND}")
#     message(STATUS "FFMPEG_INCLUDE_DIRS: ${FFMPEG_INCLUDE_DIRS}")
#     message(STATUS "FFMPEG_LIBRARY_DIRS: ${FFMPEG_LIBRARY_DIRS}")
#     message(STATUS "FFMPEG_LIBRARIES: ${FFMPEG_LIBRARIES}")
# else()
#     message(FATAL_ERROR "FFMPEG not found")
# endif()

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)


ecm_qt_declare_logging_category(KRdp
    HEADER krdp_logging.h
    IDENTIFIER KRDP
    CATEGORY_NAME org.kde.krdp
    DESCRIPTION "KRdp"
    EXPORT KRdp
    DEFAULT_SEVERITY Debug
)

                        
add_executable(rdp_demo)
target_sources(rdp_demo PRIVATE
    Server.cpp
    Server.h
    Session.cpp
    Session.h
    InputHandler.cpp
    InputHandler.h
    PeerContext.cpp
    PeerContext_p.h
    VideoStream.cpp
    VideoStream.h
    Cursor.cpp
    Cursor.h
    NetworkDetection.cpp
    NetworkDetection.h
    RDPTester.cpp
    RDPTester.h
    main.cpp
)
target_include_directories(rdp_demo PUBLIC  
    .
    ${FreeRDP_INCLUDE_DIR} ${WinPR_INCLUDE_DIR} ${FreeRDP_Server_INCLUDE_DIR}
    ${FFMPEG_INCLUDE_DIRS}
    ./build
   
)

target_link_libraries(rdp_demo
freerdp
winpr
freerdp-server
# ${FFMPEG_LIBRARIES}
avcodec
avformat
avutil
swscale
Qt${QT_MAJOR_VERSION}::Widgets
Qt${QT_MAJOR_VERSION}::Core
Qt${QT_MAJOR_VERSION}::Network
Qt${QT_MAJOR_VERSION}::Gui
# xkbcommon
XKB::XKB
)

add_subdirectory(test)


